//
//  ApplyViewController.swift
//  YueJian
//
//  Created by mac on 2017/11/9.
//  Copyright © 2017年 MapleStory. All rights reserved.
//

import UIKit

class ApplyViewController: UIViewController,UITextFieldDelegate {

    @IBOutlet weak var phone: UITextField!
    @IBOutlet weak var price: UILabel!
    @IBOutlet weak var footView: UIView!
    let money = UILabel(frame: CGRect(x: 0, y: 0, width: Screen_Width/3*2, height: 40))
    override func viewDidLoad() {
        super.viewDidLoad()
        phone.delegate = self

        let str = price.text
        let index = str?.index((str?.endIndex)!, offsetBy: -3)
        let sta = str?.substring(to: index!)
        money.text = sta
        money.backgroundColor = #colorLiteral(red: 0.1294117719, green: 0.2156862766, blue: 0.06666667014, alpha: 1)
        money.textColor = UIColor.white
        money.textAlignment = .center
        self.footView.addSubview(money)
        let settle = UIButton()
        settle.frame = CGRect(x: Screen_Width/3*2, y: 0, width: Screen_Width/3, height: 40)
        settle.backgroundColor = #colorLiteral(red: 0.2745098174, green: 0.4862745106, blue: 0.1411764771, alpha: 1)
        settle.setTitle("结算", for: .normal)
        settle.setTitleColor(UIColor.white, for: .normal)
        self.footView.addSubview(settle)
    }
    @IBOutlet weak var number: UILabel!

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    
    @IBAction func selectedButtonClick(_ sender: UIButton) {
        if sender.tag == 101 {
            let button = self.view.viewWithTag(102) as! UIButton
            sender.isSelected = true
            button.isSelected = false
        } else {
            let button = self.view.viewWithTag(101) as! UIButton
            sender.isSelected = true
            button.isSelected = false
        }
    }
    @IBAction func add(_ sender: Any) {
        let num = Int(number.text ?? "1")! + 1
        number.text = String(num)
        let str = price.text
        let index = str?.index((str?.endIndex)!, offsetBy: -3)
        let sta = str?.substring(to: index!)
        money.text = String(Double(sta!)!*Double(num))

    }
    @IBAction func minus(_ sender: Any) {
        if number.text == "0" {return}
        let num = Int(number.text ?? "1")! - 1
        number.text = String(num)
        let str = price.text
        let index = str?.index((str?.endIndex)!, offsetBy: -3)
        let sta = str?.substring(to: index!)
        money.text = String(Double(sta!)!*Double(num))
    }

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()//键盘回收
        return true
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
